﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WS.EKA.Business.Model;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;

namespace WS.EKA.UI.Business.Bussiness
{
    internal class _30DaysTrendIncident : ReportBase<List<_30DaysTrendForUI>>
    {
        public override WebSocketClientType Key
        {
            get
            {
                return WebSocketClientType.Incident_30DaysTrend;
            }
        }

        public override string GetJsonString(object parameter)
        {
            var obj = parameter as ReportParameter<List<_30DaysTrendForUI>>;
            JArray array = new JArray();
            Dictionary<string,byte> dic = new Dictionary<string,byte>(30);
            foreach (var item in obj.Data)
            {
                JArray j = new JArray();
                j.Add(item.Category);
                j.Add(item.Count);
                array.Add(j);
                dic.Add(item.Category,0);
            }

            for (int i = 0; i < 30; i++)
            {
                string item = DateTime.Now.AddDays(-i).ToString("yyyy-MM-dd");
                if (dic.ContainsKey(item))
                    continue;
                JArray j = new JArray();
                j.Add(item);
                j.Add(0);
                array.Add(j);
            }

            string str = "[" + JsonConvert.SerializeObject(array) + "]";
            var tempObj = new
            {
                ReportData = str,
                EndDate = DateTime.Now.ToString("yyyy-MM-dd"),
                StartDate = DateTime.Now.AddDays(-29).ToString("yyyy-MM-dd")
            };
            return JsonConvert.SerializeObject(tempObj);
        }
    }
}
